import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../common/index.dart';
import 'index.dart';

class RegisterPage extends GetView<RegisterController> {
  const RegisterPage({super.key});

  // 主视图
  Widget _buildView() {
    return Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage(AssetsImages.registerBg),
          fit: BoxFit.cover,
        ),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Padding(
            padding: EdgeInsets.only(left: 33.w),
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                "Sign up",
                style: TextStyle(
                  fontSize: 36.sp,
                  fontWeight: FontWeight.w900,
                  color: Color(0xFFCDFF5F),
                  fontFamily: 'Arial',
                  height: 1.0,
                  fontStyle: FontStyle.normal,
                ),
              ),
            ),
          ),
          SizedBox(height: 8.h),
          Padding(
            padding: EdgeInsets.only(left: 33.w),
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                "Enter username and password",
                style: TextStyle(
                  fontSize: 14.sp,
                  color: Color(0xFFCDFF5F),
                  fontFamily: "Manrope",
                ),
              ),
            ),
          ),
          SizedBox(height: 30.h),
          CustomInputField(
            hintText: "Input username",
            controller: controller.username_controller,
            keyboardType: TextInputType.emailAddress,
            maxLength: 12,
            buildCounter:
                (
                  context, {
                  required currentLength,
                  required isFocused,
                  maxLength,
                }) => null,
          ),
          CustomInputField(
            hintText: "Input password",
            controller: controller.password_controller,
            obscureText: true,
          ),
          CustomInputField(
            hintText: "Confirm Password",
            controller: controller.confirm_password_controller,
            obscureText: true,
          ),
          SizedBox(height: 38.h),
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 20.w),
            child: SizedBox(
              width: double.infinity,
              child: ElevatedButton(
                onPressed: controller.handle_register,
                style: ElevatedButton.styleFrom(
                  backgroundColor: Color(0xFFB4FF39),
                  padding: EdgeInsets.symmetric(vertical: 16.h),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(15.r),
                  ),
                ),
                child: Text(
                  "Sign up",
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: Colors.black87,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
          ),
          SizedBox(height: 20.h),
          Center(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  "By Continuing you agree with ",
                  style: TextStyle(
                    fontSize: 10.sp,
                    color: Colors.white.withOpacity(0.5),
                    fontWeight: FontWeight.w400,
                  ),
                ),
                InkWell(
                  onTap: () {
                    // UrlUtils.openTermsOfService();
                  },
                  child: Text(
                    "Terms of Service",
                    style: TextStyle(
                      fontSize: 10.sp,
                      color: Color(0xFFCDFF5F),
                      fontFamily: 'PingFang HK',
                      fontWeight: FontWeight.w400,
                      fontStyle: FontStyle.normal,
                      height: 16 / 10,
                      decoration: TextDecoration.underline,
                      decorationColor: Color(0xFFCDFF5F),
                      decorationStyle: TextDecorationStyle.solid,
                      decorationThickness: 1,
                    ),
                  ),
                ),
                Text(
                  " & ",
                  style: TextStyle(
                    fontSize: 10.sp,
                    color: Colors.white.withOpacity(0.5),
                    fontWeight: FontWeight.w400,
                  ),
                ),
                InkWell(
                  onTap: () {
                    // UrlUtils.openPrivacyPolicy();
                  },
                  child: Text(
                    "Privacy Policy",
                    style: TextStyle(
                      fontSize: 10.sp,
                      color: Color(0xFFCDFF5F),
                      fontFamily: 'PingFang HK',
                      fontWeight: FontWeight.w400,
                      fontStyle: FontStyle.normal,
                      height: 16 / 10,
                      decoration: TextDecoration.underline,
                      decorationColor: Color(0xFFCDFF5F),
                      decorationStyle: TextDecorationStyle.solid,
                      decorationThickness: 1,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<RegisterController>(
      init: RegisterController(),
      id: "register",
      builder: (_) {
        return GestureDetector(
          onTap: () => FocusScope.of(context).unfocus(),
          child: Scaffold(
            resizeToAvoidBottomInset: false,
            body: SafeArea(top: false, bottom: false, child: _buildView()),
          ),
        );
      },
    );
  }
}
